package com.ruoyi.xsp.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.xsp.domain.XspUserAuth;
import com.ruoyi.xsp.service.IXspUserAuthService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 第三方登录Controller
 * 
 * @author zhiminhu
 * @date 2021-01-22
 */
@Controller
@RequestMapping("/xsp/auth")
public class XspUserAuthController extends BaseController
{
    private String prefix = "xsp/auth";

    @Autowired
    private IXspUserAuthService xspUserAuthService;

    @RequiresPermissions("xsp:auth:view")
    @GetMapping()
    public String auth()
    {
        return prefix + "/auth";
    }

    /**
     * 查询第三方登录列表
     */
    @RequiresPermissions("xsp:auth:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(XspUserAuth xspUserAuth)
    {
        startPage();
        List<XspUserAuth> list = xspUserAuthService.selectXspUserAuthList(xspUserAuth);
        return getDataTable(list);
    }

    /**
     * 导出第三方登录列表
     */
    @RequiresPermissions("xsp:auth:export")
    @Log(title = "第三方登录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(XspUserAuth xspUserAuth)
    {
        List<XspUserAuth> list = xspUserAuthService.selectXspUserAuthList(xspUserAuth);
        ExcelUtil<XspUserAuth> util = new ExcelUtil<XspUserAuth>(XspUserAuth.class);
        return util.exportExcel(list, "auth");
    }

    /**
     * 新增第三方登录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存第三方登录
     */
    @RequiresPermissions("xsp:auth:add")
    @Log(title = "第三方登录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(XspUserAuth xspUserAuth)
    {
        return toAjax(xspUserAuthService.insertXspUserAuth(xspUserAuth));
    }

    /**
     * 修改第三方登录
     */
    @GetMapping("/edit/{userCode}")
    public String edit(@PathVariable("userCode") Long userCode, ModelMap mmap)
    {
        XspUserAuth xspUserAuth = xspUserAuthService.selectXspUserAuthById(userCode);
        mmap.put("xspUserAuth", xspUserAuth);
        return prefix + "/edit";
    }

    /**
     * 修改保存第三方登录
     */
    @RequiresPermissions("xsp:auth:edit")
    @Log(title = "第三方登录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(XspUserAuth xspUserAuth)
    {
        return toAjax(xspUserAuthService.updateXspUserAuth(xspUserAuth));
    }

    /**
     * 删除第三方登录
     */
    @RequiresPermissions("xsp:auth:remove")
    @Log(title = "第三方登录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(xspUserAuthService.deleteXspUserAuthByIds(ids));
    }
}
